const joi = require('joi');
const validationMiddleware = require('../../middleware/validate');
const evaluationController = require('../../controllers/good/evaluationController');
const router = require('koa-router')();
router.prefix('/evaluation');
const { verify } = require('../../utils/auth');
router.use(verify);
const rulesSchema = {
    '/evaluation/addevaluation':
        joi.array().items(
            joi.object({
                goodId: joi.string().required().label('商品ID'),
                basetags: joi.array().items(joi.string()).label('基础标签'),
                ratingtags: joi.array().items(joi.string()).label('评分标签'),
                rating: joi.number().min(1).max(5).required().label('评分'),
                comment: joi.string().allow('').label('评论'),
                images: joi.array().items(joi.string()).label('图片链接数组')
            })
        ).required().label('评价数据数组'),
    '/evaluation/updateevaluation': joi.object({
        id: joi.string().required().label('评价ID'),
        evaluations: joi.array().items(
            joi.object({
                goodId: joi.string().required().label('商品ID'),
                basetags: joi.array().items(joi.string()).label('基础标签'),
                ratingtags: joi.array().items(joi.string()).label('评分标签'),
                rating: joi.number().min(1).max(5).required().label('评分'),
                comment: joi.string().allow('').label('评论'),
                images: joi.array().items(joi.string()).label('图片链接数组')
            })
        ).required().label('评价数据数组')
    }),
    '/evaluation/getevaluation': joi.object({
        id: joi.string().required().label('评价ID')
    }),
    '/evaluation/deleteevaluation': joi.object({
        id: joi.string().required().label('评价ID')
    }),
};
router.post('/addevaluation', validationMiddleware(rulesSchema), evaluationController.createEvaluation);
router.post('/updateevaluation', validationMiddleware(rulesSchema), evaluationController.updateEvaluation);
router.post('/getevaluation', validationMiddleware(rulesSchema), evaluationController.getEvaluationById);
router.post('/deleteevaluation', validationMiddleware(rulesSchema), evaluationController.deleteEvaluation);
router.post('/getevaluationlist', evaluationController.getEvaluationList);
module.exports = router;